<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div>
            <span>用户名：</span>
            <span><input type="text" v-model.lazy="uname"></span>
            <span>{{tip}}</span>
        </div>
    </div>
    <script src="../vue.min.js"></script>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                uname: '',
                tip: ''
            },
            methods: {
                checkName: function (uname) {
                    var that = this;
                    setTimeout(function () {
                        if (uname == 'admin') {
                            that.tip = '用户名存在'
                        } else {
                            that.tip = 'ok'
                        }
                    }, 2000)
                }
            },
            watch: {
                uname: function (val) {
                    this.checkName(val);
                    this.tip = '正在验证'
                }
            }
        })
    </script>
</body>

</html>